//
//  HgTableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/3/7.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "HgTableViewCell.h"

@implementation HgTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.label1 = [[BaseLabel alloc] init];
        [self.contentView addSubview:_label1];
        [_label1 release];
        
        
        self.imageHeader = [[UIImageView alloc] init];
        [self.contentView addSubview:_imageHeader];
        [_imageHeader release];
        
        
        self.switch1 = [[UISwitch alloc] init];
        [_switch1 addTarget: self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:_switch1];
        [_switch1 release];
        
        
        //设默认值
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"yeJianMoShi"] isEqualToString:@"isDay"]) {
            
            _switch1.on = NO;
        }else{
            _switch1.on = YES;
        }
        
        [self yanXianPanDuan];
    }
    return self;
}

- (void)switchAction:(UISwitch *)swecth{
    
    
    
    if (swecth.on == NO) {
        [[NSUserDefaults standardUserDefaults] setObject:@"isDay" forKey:@"yeJianMoShi"];
        
    }else{
        [[NSUserDefaults standardUserDefaults] setObject:@"isNight" forKey:@"yeJianMoShi"];
    }
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"yeJianMoShi" object:nil];
    
}

- (void)yanXianPanDuan{
    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"yeJianMoShi"];
    
    if ([str isEqualToString:@"isDay"]) {
        _switch1.on = NO;
    }else{
        _switch1.on = YES;
    }
}




- (void)layoutSubviews{
    
    
    _imageHeader.frame =  CGRectMake(15, 5, 40, 40);

    
    _label1.frame = CGRectMake(80, 5, 100, 40);
    _switch1.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 70, 10, 70, 50);
    
    
}



- (void)dealloc{
    [_label1 release];
    [_switch1 release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
